﻿/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2014/3/15
 * 时间: 23:28
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */

using System;

namespace Step
{
	public class Queue
	{
		Entry first;
		Entry top;
		
		public void Push(object data) {	
			top = new Entry(top, data);
			if(first == null) {
				first = top;
			}
		}
		
		public object Pop() {
			if(first == null) throw new InvalidOperationException();
			object result = first.data;
			first = first.next;
			
			return result;
		}
		
		class Entry 
		{
			public Entry next;
			public object data;
			
			public Entry (Entry top, object data) {
				if(top == null) {					
					this.data = data;
					top = this;
				} else {
					this.data = data;
					top.next = this;
				}
			}
		}
	}
}